package com.longrise.android.byjk.plugins.aboutme.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.longrise.android.byjk.R;
import com.longrise.android.byjk.model.Consum;
import com.longrise.android.byjk.widget.recyclerviewadapter.SimpleArrayAdapter;

/**
 * Created by godliness on 2017/3/6.
 */

public class ConsumAdapter extends SimpleArrayAdapter<Consum> {

    private static final String TAG = "ConsumAdapter";

    @Override
    protected BaseRecyclerViewHolder onCreateContentItemViewHolder(ViewGroup parent, int viewType) {
        return new ConsumViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.consumehistory_item, parent, false));
    }

    @Override
    protected void onBindContentView(BaseRecyclerViewHolder holder, int position) {
        ConsumViewHolder viewHolder = (ConsumViewHolder) holder;
        Consum consum = getItem(position);
        if (consum != null) {
            viewHolder.mText_Title.setText("课程名称：" + consum.subject);
            viewHolder.mText_Code.setText("订单号：" + consum.out_trade_no);
            String time = consum.endtime;
            if (time.length() > 19) {
                viewHolder.mText_Time.setText("时\u3000间：" + time.substring(0, 19));
            } else {
                viewHolder.mText_Time.setText("时\u3000间：" + consum.endtime);
            }
            viewHolder.mText_Value.setText("金\u3000额：" + consum.total_fee + "元");
            String from = consum.trade_type;
            if (from.equals("APP")) {
                viewHolder.mText_From.setText("来\u3000源：保宝" + from);
            } else {
                viewHolder.mText_From.setText("来\u3000源：保宝网");
            }
        }
    }

    @Override
    protected int getContentItemViewType(int position) {
        return 0;
    }

    private class ConsumViewHolder extends BaseRecyclerViewHolder {

        private TextView mText_Title;
        private TextView mText_Code;
        private TextView mText_Time;
        private TextView mText_Value;
        private TextView mText_From;

        public ConsumViewHolder(View itemView) {
            super(itemView);
            mText_Title = (TextView) itemView.findViewById(R.id.text_from_title);
            mText_Code = (TextView) itemView.findViewById(R.id.text_from_code);
            mText_Time = (TextView) itemView.findViewById(R.id.text_from_time);
            mText_Value = (TextView) itemView.findViewById(R.id.text_from_value);
            mText_From = (TextView) itemView.findViewById(R.id.text_value_from);
        }
    }
}
